<template>
  <div>
    <!-- 标签或分类名 -->
    <div
      class="banner"
      :style="cover"
    >
      <h1 class="banner-title animated fadeInDown">
        {{ title }}
      </h1>
      <!-- 主屏幕副标题 -->
      <div class="banner-title-second">
        <span v-if="currentPageInfo.pageIntro" >
          {{ currentPageInfo.pageIntro }}
        </span>
      </div>
    </div>
    <div class="article-list-wrapper">
      <v-row>
        <v-col
          v-for="item of articleList"
          :key="item.id"
          md="4"
          cols="12"
        >
          <!-- 文章 -->
          <v-card
            class="animated zoomIn article-item-card"
            @click="toArticleInfo(item.id)"
          >
            <div class="article-item-cover">
              <v-img
                class="on-hover"
                width="100%"
                height="100%"
                :src="item.headerImg"
              />
            </div>
            <div class="article-item-info">
              <!-- 文章标题 -->
              <div>
                <router-link :to="'/articles/' + item.id">
                  {{ item.title }}
                </router-link>
              </div>
              <div style="margin-top:0.375rem">
                <!-- 发表时间 -->
                <v-icon size="20">
                  mdi-clock-outline
                </v-icon>
                {{ item.createTime | date }}
                <!--                <span  class="float-right">{{item.browseNum}}</span>-->
              </div>
            </div>
          </v-card>
        </v-col>
      </v-row>
      <!-- 无限加载 -->
      <infinite-loading @infinite="initArticleList">
        <div slot="no-results" />
        <div slot="no-more" />
      </infinite-loading>
    </div>
  </div>
</template>

<script>
import {metaInfo} from '@/config/BlogConstant'
import {articleList} from '@/api'
export default {
  metaInfo:metaInfo,
  data: function() {
    return {
      current: 1,
      img: process.env.VUE_APP_IMG_API,
      size: 6,
      articleList: [],
      name: '',
      title: '',
      params: {
        page: 1,
        size: 5,
        sort: 'a.isTop,a.id',
        order: 'desc,desc',
        connector: 'or',
        query: []
      },
      currentPageInfo:{},
      tagList:[]
    }
  },
  computed: {
    cover() {
      let cover = ''
      this.$store.state.blogInfo.pageInfo.forEach(item => {
        if (item.pageKey === 'articleList') {
          cover = item.headerImgUrl
          this.currentPageInfo = item
        }
      })
      return 'background: url(' + cover + ') center center / cover no-repeat'
    }
  },
  created() {
    const path = this.$route.path
    this.getList()
    if (this.$route.params.tagId){
      let tagId = parseInt(this.$route.params.tagId)
      if (tagId !== 0){
        this.params.query.push({
          name: 'a.articleType',
          type: 'Short',
          operator: 'EQ',
          value: this.$route.params.tagId
        })
      }
    }
  },
  methods: {
    initArticleList($state) {
      articleList(this.params).then(res => {
        let data = res.data.data.rows
        document.title = this.title
        if (data.length) {
          this.params.page++
          this.articleList.push(...data)
          $state.loaded()
        } else {
          $state.complete()
        }
      })
    },
    getList(){
      this.tagList = this.$store.state.blogInfo.articleTypes
      this.tagList.forEach(e =>{
        if (e.id === parseInt(this.$route.params.tagId) ){
          this.title = e.typeValue
        }
      })
    },
    toArticleInfo(id){
      this.$router.push(`/articles/${id}`)
    }
  },
}
</script>

<style scoped>
@media (min-width: 760px) {
  .article-list-wrapper {
    max-width: 1106px;
    margin: 370px auto 1rem auto;
  }
  .article-item-card:hover {
    transition: all 0.3s;
    box-shadow: 0 4px 12px 12px rgba(7, 17, 27, 0.15);
  }
  .article-item-card:not(:hover) {
    transition: all 0.3s;
  }
  .article-item-card:hover .on-hover {
    transition: all 0.6s;
    transform: scale(1.1);
  }
  .article-item-card:not(:hover) .on-hover {
    transition: all 0.6s;
  }
  .article-item-info {
    line-height: 1.7;
    padding: 15px 15px 12px 18px;
    font-size: 15px;
  }
}
@media (max-width: 759px) {
  .article-list-wrapper {
    margin-top: 230px;
    padding: 0 12px;
  }
  .article-item-info {
    line-height: 1.7;
    padding: 15px 15px 12px 18px;
  }
}
.article-item-card {
  border-radius: 8px !important;
  box-shadow: 0 4px 8px 6px rgba(7, 17, 27, 0.06);
}
.article-item-card a {
  transition: all 0.3s;
}
.article-item-cover {
  height: 220px;
  overflow: hidden;
}
.article-item-card a:hover {
  color: #8e8cd8;
}
.tag-wrapper {
  padding: 10px 15px 10px 18px;
}
.tag-wrapper a {
  color: #fff !important;
}
.tag-btn {
  display: inline-block;
  font-size: 0.725rem;
  line-height: 22px;
  height: 22px;
  border-radius: 10px;
  padding: 0 12px !important;
  background: linear-gradient(to right, #bf4643 0%, #6c9d8f 100%);
  opacity: 0.6;
  margin-right: 0.5rem;
}
</style>
